//
//  UserHeadInfoCell.m
//  HotWord
//
//  Created by Rainbow on 7/26/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "UserHeadInfoCell.h"

@implementation UserHeadInfoCell
@synthesize nickNameTextField;
@synthesize headImageView;
@synthesize delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UITapGestureRecognizer *tapGesture1 = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnHeadImage1)] autorelease];
    self.headImageView.userInteractionEnabled = YES;
    [self.headImageView addGestureRecognizer:tapGesture1];
    
    UITapGestureRecognizer *tapGesture2 = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnHeadImage2)] autorelease];
    self.headImageView1.userInteractionEnabled = YES;
    [self.headImageView1 addGestureRecognizer:tapGesture2];
    
    
    UITapGestureRecognizer *tapGesture3 = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnHeadImage3)] autorelease];
    self.headImageView2.userInteractionEnabled = YES;
    [self.headImageView2 addGestureRecognizer:tapGesture3];
    
    nickNameTextField.delegate = self;
}

- (void)tapOnHeadImage1
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserHeadInfoCellHeadDidSelected:selectIndex:)]) {
        [self.delegate UserHeadInfoCellHeadDidSelected:self selectIndex:0];
    }
}

- (void)tapOnHeadImage2
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserHeadInfoCellHeadDidSelected:selectIndex:)]) {
        [self.delegate UserHeadInfoCellHeadDidSelected:self selectIndex:1];
    }
}

- (void)tapOnHeadImage3
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserHeadInfoCellHeadDidSelected:selectIndex:)]) {
        [self.delegate UserHeadInfoCellHeadDidSelected:self selectIndex:2];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setUser:(User *)user
{
    self.nickNameTextField.text = user.nickname;
    [self.headImageView setDefaultImage:[UIImage imageNamed:@"photo_card.png"]];
    [self.headImageView loadImage:user.avater];
    [self.headImageView1 setDefaultImage:[UIImage imageNamed:@"photo_card.png"]];
    [self.headImageView1 loadImage:user.avater1];
    [self.headImageView2 setDefaultImage:[UIImage imageNamed:@"photo_card.png"]];
    [self.headImageView2 loadImage:user.avater2];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserInfoCellBeginEdit:)]) {
        [self.delegate UserHeadInfoCellBeginEdit:self];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserInfoCellEndEdit:)]) {
        [self.delegate UserHeadInfoCellEndEdit:self];
    }
}

-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(UserInfoCellEndEdit:)]) {
        [self.delegate UserHeadInfoCellEndEdit:self];
    }
    [self.nickNameTextField resignFirstResponder];
    return NO;
}


- (void)dealloc {
    [headImageView release];
    [nickNameTextField release];
    [_headImageView1 release];
    [_headImageView2 release];
    [super dealloc];
}
@end
